﻿using System;
using System.Collections;
using System.Web;
using System.Web.Caching;
using System.Web.SessionState;

namespace FBGraph.Web
{
    public class ClassicHttpContextWrapper : IHttpContextWrapper
    {
        private HttpContext httpContext;
        private ClassicHttpRequestWrapper request;
        private ClassicHttpResponseWrapper response;
        private ClassicHttpSessionStateWrapper session;

        public void Init(HttpContext httpContext)
        {
            this.httpContext = httpContext;
            this.request = new ClassicHttpRequestWrapper(this.httpContext.Request);
            this.response = new ClassicHttpResponseWrapper(this.httpContext.Response);
            this.session = new ClassicHttpSessionStateWrapper(this.httpContext.Session);
        }

        void IHttpContextWrapper.Init(Object httpContext)
        {
            if (httpContext is HttpContext)this.Init((HttpContext)httpContext);
            else throw new ArgumentException("httpContext must be a reference to an instance of System.Web.HttpContext");
        }

        public Cache Cache { get { return httpContext.Cache; } }

        public IDictionary Items { get { return httpContext.Items; } }

        public ClassicHttpSessionStateWrapper Session { get { return this.session; } }
        IHttpSessionStateWrapper IHttpContextWrapper.Session { get { return this.session; } }

        public ClassicHttpRequestWrapper Request { get { return this.request; } }
        IHttpRequestWrapper IHttpContextWrapper.Request { get { return this.request; } }

        public ClassicHttpResponseWrapper Response { get { return this.response; } }
        IHttpResponseWrapper IHttpContextWrapper.Response { get { return this.response; } }
    }
}